// Provider层
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';

// Injectable 表示此provider可以被注入到controller中
@Injectable()
export class TestService {
  getTest(params: Record<string, any>): object {
    if (!params.id && !Number.isInteger(params.id)) {
      throw new HttpException(
        '必须包含id参数，并且id为数字',
        HttpStatus.BAD_REQUEST,
      );
    }
    return {
      type: 'data',
      param: params.id,
      testService: '依赖注入测试 Test Service!',
    };
  }
}
